package com.ruoyi.kenuo.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.kenuo.service.impl.MqttPublisher;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/device")
public class DeviceController {




    @Resource
    private MqttPublisher mqttPublisher;

    /**
     * 测试发布消息
     */
    @GetMapping("/publish")
    public AjaxResult publish(@RequestParam String topic, @RequestParam String message) {
        mqttPublisher.publish(topic, message);
        return AjaxResult.success("消息已发布");
    }


    /**
     * 订阅消息主题
     */
    @GetMapping("/subScribe")
    public AjaxResult subScribe(@RequestParam String topic) {
        mqttPublisher.subScribe(topic);
        return AjaxResult.success("主题已订阅");
    }

    /**
     * 取消订阅消息主题
     */
    @GetMapping("/unSubScribe")
    public AjaxResult unSubScribe(@RequestParam String topic) {
        mqttPublisher.CancelSubScribe(topic);
        return AjaxResult.success("已取消订阅");
    }
}
